<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>发改局</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome Icons -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- IonIcons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">

  <script>
    // 企业行记录删除
    function deleteThisRowPapser(id) {
      $.ajax({
        url:"/en/enterprise/" + id,
        type:"DELETE",
        contentType:"application/json",//设置请求参数类型为json字符串
        // data:JSON.stringify(jsonstr),//将json对象转换成json字符串发送
        dataType:"json",
        success:function(result){

        },
      });
    }
  </script>
</head>


<body class="hold-transition sidebar-mini">
<div class="wrapper">

  <!-- 主内容容器 -->
  <div class="content-wrapper">
    <!-- 容器头标题 -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">企业信息</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">首页</a></li>
              <li class="breadcrumb-item active">企业信息</li>
            </ol>
          </div>
        </div>
      </div>
    </div>

    <!-- 主题内容正文 -->
    <section class="content">
      <div class="container-fluid">

        <div class="row">
          <div class="col-12">
            <div class="card">
              <div class="card-body">


                <!-- 表格顶部企业搜索 -->
                <div class="form-group" style="display: flex;">
                  <label style="padding-top: 2px;">企业搜索</label>

                  <div class="navbar-search-block" style="margin-left: 20px;">
                    <form class="form-inline">
                      <div class="input-group input-group-sm">
                        <input class="form-control form-control-navbar" type="search" placeholder="请输入企业名"
                               aria-label="Search" id="search">
                        <div class="input-group-append" style="margin-left: 10px;">
                          <button class="btn btn-navbar" onclick="search1()" type="button">
                            <i class="fas fa-search"></i>
                          </button>
                          <button class="btn btn-navbar" type="button" data-widget="navbar-search" onclick="clearSearch()">
                            <i class="fas fa-times"></i>
                          </button>

                        </div>
                        <div style="margin-left: 10px;">
                          <button type="button" onclick="search1()" class="btn btn-primary btn-sm">搜索</button>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>


                <table id="example2" class="table table-bordered table-hover">
                  <thead>
                  <tr>
                    <th style>主企业</th>
                    <th>子企业</th>
<!--                    <th style="width: 230px;">企业住所</th>-->
<!--                    <th>所属行业</th>-->
                    <th>企业负责人姓名</th>
                    <th>企业联系电话</th>
                    <th>项目上报人</th>
                    <th>项目上报人职务</th>
                    <th>项目上报人电话</th>
<!--                    <th>总投资(万元)</th>-->
                    <th>是否运营</th>
                    <th style="width: 170px;">操作</th>
                  </tr>
                  </thead>
                  <tbody>

                  </tbody>
                  <tfoot>
                      <tr>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
                          <th></th>
<!--                          <th></th>-->
<!--                          <th></th>-->
<!--                          <th></th>-->
                      </tr>
                  </tfoot>
                </table>
              </div>
            </div>

          </div>
        </div>
      </div>
    </section>
  </div>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
  </aside>

  <!-- 版权信息 -->
  <footer class="main-footer">
    <strong>Copyright &copy; 2021 <a href="http://www.chengzhouyun.com/" target="_blank">澄州云</a>.</strong> All rights
    reserved.
    <div class="float-right d-none d-sm-inline-block">
      <b>Version</b> 1.0
    </div>
  </footer>

</div>

<!-- REQUIRED SCRIPTS -->
<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE -->
<script src="../dist/js/adminlte.js"></script>

<!-- OPTIONAL SCRIPTS -->
<script src="../plugins/chart.js/Chart.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="../dist/js/pages/dashboard3.js"></script>
</body>

<!-- DataTables  & Plugins -->
<script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../../plugins/jszip/jszip.min.js"></script>
<script src="../../plugins/pdfmake/pdfmake.min.js"></script>
<script src="../../plugins/pdfmake/vfs_fonts.js"></script>
<script src="../../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../../plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>

<script th:inline="javascript">
    // 表格变量
    var table;
    // 金钱格式化
    function number_format(number, decimals, dec_point, thousands_sep) {
        /*
        * 参数说明：
        * number：要格式化的数字
        * decimals：保留几位小数
        * dec_point：小数点符号
        * thousands_sep：千分位符号
        * */
        number = (number + '').replace(/[^0-9+-Ee.]/g, '');
        var n = !isFinite(+number) ? 0 : +number,
            prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
            sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
            dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
            s = '',
            toFixedFix = function (n, prec) {
                var k = Math.pow(10, prec);
                return '' + Math.ceil(n * k) / k;
            };

        s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
        var re = /(-?\d+)(\d{3})/;
        while (re.test(s[0])) {
            s[0] = s[0].replace(re, "$1" + sep + "$2");
        }

        if ((s[1] || '').length < prec) {
            s[1] = s[1] || '';
            s[1] += new Array(prec - s[1].length + 1).join('0');
        }
        return s.join(dec);
    }

    // 表格搜索
    function search1()
    {
        table.ajax.reload();
    }

    // 搜索框清除内容
    function clearSearch() {
        $('#search').val('');
    }



  $(document).ready(function () {

    var arr_ids = new Array();

    // 表格数据展示配置  相关信息可以查看http://datatables.club/
      table = $('#example2').DataTable({
        dom: 'Bfrtip',
      // buttons: ['copy', 'excel', 'pdf'],
      processing : true,
      // 开启服务器端分页
      serverSide : true,
      sort: false,
      searchable: true,
      autoWidth: false,
      ajax:{
        type:"get",
        url:'/en/enterprise/list',
        dataSrc: 'data',
        data: function (param) {
            var search = $('#search').val();
            //添加参数传给服务器
            param.search = search;
            return param;
        }

      },
      // 渲染提高性能
      deferRender: true,
      footerCallback: function(tfoot, data, start, end, display) {
          var totalInvestmentSum = 0;

          // 循环遍历数据进行合计计算
          for(var i =0; i< data.length; i++) {
              totalInvestmentSum += data[i].totalInvestment;
          }
          // 表格底部填充计算数据
          $(tfoot).find('th').eq(0).html("合计");
          $(tfoot).find('th').eq(4).html(number_format(totalInvestmentSum,2,".",","));

      },
      columns:[
        {data:"enName"
            // visible:false
        },
        {data:"sub_en_name",
        "render":function(data, type,row){
          // console.log("子企业");
          // console.log("data:"+data)
          var subEn = "";
          if (data != null){
            for(var i=0;i<data.length;i++){
              if(i == data.length-1){
                subEn = subEn + data[i]
              }else{
                subEn = subEn +  data[i] + " | "
              }
            }
          }
          return subEn;
        }
        },
        // {data:"address"},
        // {data:"industry"},
        {data:"enPersionName"},
        {data:"enTel"},
        {data:"projectReportPerson"},
        {data:"projectReportPersonPost"},
        {data:"projectReportPersonTel"},
        // {data:"totalInvestment"},
        {data:"enable",
            // 默认值
            // defaultContent:"",
            "render" : function (data) {
                return data == 1 ? "是" : "否";
            }
        }
      ],
        "aoColumnDefs":[//设置列的属性，此处设置第一列不排序
          {"bSortable": false, "aTargets": [0]},{ "class": "tn", "targets": [ 0 ] },
          {

            "targets": 8,
            "class": "but_xq",
            "data": null,
            "bSortable": false,
            "render" : function(data, type,row) {
                // data 和 row 都是每行数据 里面存有id
                // var id = '"' + row.id + '"';
              var role_id  = /*[[${#httpSession.getAttribute('role_id')}]]*/{};
              console.log(role_id)
              var html = "<a href='/page/EnterpriseDetail/" + row.id + "' class='up btn btn-default btn-xs'><i class='fas fa-info-circle'></i>详情</a>"
                html += "<a href='/page/EnterpriseChange/" + row.id + "' class='up btn btn-default btn-xs'><i class='fas fa-edit'></i>编辑</a>"
              if (role_id != 1 & row.jltj == 1){
                console.log(role_id)

              }else {
                html += "<a style='background-color: #fbbcbc;' id='del_"+ row.id +"' href=\"#\" class='down btn btn-default btn-xs'><i class='fa fa-times'></i>删除</a>"
              }


              /**
               * 删除
               */
              // render 渲染事件莫名奇妙 会走三次 每个事件会注册三次
              // 先取这个值
              var r = arr_ids.indexOf(row.id);
              // 如果这个值不存在
              if (r == -1) {
                // 添加到数组中
                arr_ids.push(row.id);

                $('#example2 tbody').on('click', 'a#del_'+row.id, function () {

                  var r = confirm("您确定要删除?");

                  if (r == true){

                    $.ajax({
                      url:'/en/enterprise/'+row.id,
                      type:'DELETE',
                      dataType:'json',
                      contentType:'application/json',
                      async: false,
                      success:function(res){

                        if(res.statusCode == 200) {
                          alert(res.message);
                        } else{
                          alert(res.errorMsg);
                        }
                        // 重载页面
                        location.reload()
                      },
                    })

                  }

                });
              }

              return html;
            }
          }
        ],

      // 显示语言
      "language": {
          zeroRecords:"没有匹配结果",
          emptyTable:"没有匹配结果",
          infoEmpty:"无符合条件记录",
          info: "显示第 _START_ 至 _END_ 条结果，共_TOTAL_条记录",
          lengthMenu: "每页显示 _MENU_ 条记录",
          paginate: {"first": "首页 ", "last": "末页", "next": "下一页", "previous": "上一页"}
      },

      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });

    /**
     * 查看修改
     */
    // $('#example2 tbody').on( 'click', 'a#edit', function () {
    //
    //   alert("查看修改：");
    // } );

    //监听一下上一页下一页的点击事件
    // $(".dataTables_paginate").on("click", "a", function() {
    //
    //   // alert("点击了上一页和下一页的按钮");
    //   ifRefresh = false;//点击了页码切换的按钮,则重新设置可以刷新宽度的函数
    // });

    // 移除搜索框的右边隐藏样式
    $('#search').removeClass("form-control-navbar")
  });
</script>

</html>
